<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="用户姓名">
          <el-input
            v-model="form.nickname"
            placeholder="请输入用户姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户ID">
          <el-input v-model="form.uid" placeholder="请输入用户ID"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          :index="Method"
          type="index"
          prop="id"
          width="70"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="nickname" align="center" label="用户姓名">
        </el-table-column>
        <el-table-column prop="uid" align="center" label="用户ID">
        </el-table-column>
        <el-table-column prop="count(1)" align="center" label="评价次数">
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row)"
              size="mini"
              type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>

    <el-dialog
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
    >
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="packGit"
        border
        max-height="500"
        style="width: 100%"
      >
        <!-- <el-table-column
          label="序号"
          type="index"
          width="55"
          :index="Method"
          align="center"
        >
        </el-table-column> -->
        <el-table-column prop="id" align="center" label="ID" width="70">
        </el-table-column>
        <el-table-column
          prop="housing_source_title"
          align="center"
          label="标题"
        >
        </el-table-column>
        <el-table-column prop="nickname" align="center" label="评价人">
        </el-table-column>
        <el-table-column prop="uid" align="center" label="评论人ID">
        </el-table-column>
        <el-table-column
          prop="tags"
          align="center"
          label="服务标签"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="content"
          align="center"
          label="评价内容"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column prop="score" align="center" label="评价分数">
        </el-table-column>
        <el-table-column prop="img_waiguan" align="center" label="外观照片">
          <template slot-scope="scope">
            <div
              v-if="
                scope.row.img_waiguan != '' && scope.row.img_waiguan != null
              "
            >
              <el-image
                v-for="(item, index) in scope.row.img_waiguan.split(',')"
                :key="index"
                style="width: 25px; height: 25px; margin-right: 5px"
                :src="imgHeader + item"
                :preview-src-list="[imgHeader + item]"
                fit="cover"
              ></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="img_waiguan" align="center" label="现场照片">
          <template slot-scope="scope">
            <div
              v-if="
                scope.row.img_xianchang != '' && scope.row.img_waiguan != null
              "
            >
              <el-image
                v-for="(item, index) in scope.row.img_xianchang.split(',')"
                :key="index"
                style="width: 25px; height: 25px; margin-right: 5px"
                :src="imgHeader + item"
                :preview-src-list="[imgHeader + item]"
                fit="cover"
              ></el-image>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="comment_time" align="center" label="评价时间">
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              @click="handleDelete(scope.row)"
              size="mini"
              type="danger"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"
          :current-page="page1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total1"
        >
        </el-pagination>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  packageCount,
  packageIndex,
  classification,
} from "../../../utils/api.js";
import {
  houseEvaluateList,
  houseEvaluateListDetail,
  houseEvaluateListDetailDel,
} from "../../../utils/main";
export default {
  data() {
    return {
      Data: [
        {
          name: "水票",
          id: "1",
        },
      ],
      money: "",
      token: sessionStorage.getItem("token"),
      //请求特效
      loading: false,
      //弹窗
      dialogVisible: false,
      form: {
        nickname: "",
        uid: "",
        time: "",
      },
      imgHeader: this.Global.imgHeader,

      time: "",
      //发送请求时间参数
      //展示数据
      tableData: [
        // {
        //   water_name: "",
        //   goods_cat_name: "",
        //   water_number: "",
        //   id: "",
        //   brand_name: "",
        //   goods_name: "",
        //   water_img: "",
        //   ctime: "",
        //   buy_count: "",
        //   water_cat_id: "",
        //   ctime: "",
        // },
      ],
      //明细
      packGit: [
        //   {
        //     water_nameL: "",
        //     goods_cat_name: "",
        //     package_nember: "",
        //     goods_name: "",
        //     brand_name: "",
        //     water_img: "",
        //     ctime: "",
        //     payed: "",
        //   },
      ],
      uid: "",
      page: 1,
      limit: 10,
      total: 0,
      page1: 1,
      limit1: 10,
      total1: 0,
      name: "",
      type: "",
      order_id: 0,
    };
  },
  methods: {
    //日期
    timeChange(e) {
      // console.log(e);
      // let list = [];
      // e.forEach((item) => {
      //   let date = new Date(item);
      //   let year = date.getFullYear();
      //   let month = date.getMonth() + 1;
      //   let day = date.getDate();
      //   let h = date.getHours();
      //   let min = date.getMinutes();
      //   let s = date.getSeconds();
      //   month = month < 10 ? "0" + month : month;
      //   day = day < 10 ? "0" + day : day;
      //   h = h < 10 ? "0" + h : h;
      //   min = min < 10 ? "0" + min : min;
      //   s = s < 10 ? "0" + s : s;
      //   list.push(
      //     year + "-" + month + "-" + day + " " + h + ":" + min + ":" + s
      //   );
      // });

      // this.time = list[0] + "," + list[1];
      // console.log(this.time);
      this.time = this.form.time;
      if (this.form.time == null) {
        this.time = "";
      }
      this.getList();
    },
    //查询
    onSubmit(row) {
      // this.name = this.form.name;
      // this.time = this.form.time;
      // if (this.time == null) {
      //   this.time = "";
      // }
      // this.type = this.form.type;
      this.page = 1;
      this.getList();
    },
    onReset() {
      this.form.nickname = "";
      this.form.uid = "";
      this.getList();
    },
    //水票分类
    // selectChange() {},
    //分页器
    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    handleSizeChange1(val) {
      this.limit1 = val;
      this.houseEvaluateDetail(this.uid);
    },
    handleCurrentChange1(val) {
      this.page1 = val;
      this.houseEvaluateDetail(this.uid);
    },
    // 序号排序
    Method(index) {
      if (this.token < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },

    // 获取水票出售列表
    async getList() {
      this.loading = true;
      let res = await houseEvaluateList(
        this.token,
        this.form.uid,
        this.form.nickname,
        this.page,
        this.limit
      );
      if (res.data.status) {
        this.tableData = res.data.data.data || [];
        this.total = res.data.data.count;
        this.money = res.data.data.sum;
        this.tableData.forEach((item) => {
          if (item.order_items != null && item.bill_aftersales_itemss == null) {
            item.sellingCount = item.order_items.nums;
            item.sellingMoney = item.order_items.amount;
          } else if (
            item.order_items != null &&
            item.bill_aftersales_itemss != null
          ) {
            item.sellingCount =
              item.order_items.nums - item.bill_aftersales_itemss.nums;
            item.sellingMoney =
              item.order_items.amount - item.bill_aftersales_itemss.amount;
          } else if (
            item.order_items == null &&
            item.bill_aftersales_itemss == null
          ) {
            item.sellingCount = "0";
            item.sellingMoney = "0.00";
          }
        });
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    handleDelete(row) {
      this.$confirm("此操作将永久删除该评价, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          houseEvaluateListDetailDel(this.token, row.id).then((res) => {
            if (res.data.status) {
              this.$message({
                type: "success",
                message: "删除成功",
              });
              this.houseEvaluateDetail(this.uid);
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 点击详情的事件
    handleClick(row) {
      let obj = JSON.parse(JSON.stringify(row));
      // this.tableData.water_cat_id = obj.water_cat_id;
      // this.tableData.id = obj.id;
      // this.packageIndexs();
      this.dialogVisible = true;
      this.uid = obj.uid;
      this.houseEvaluateDetail(this.uid);
    },
    async houseEvaluateDetail(id) {
      let res = await houseEvaluateListDetail(
        this.token,
        id,
        this.page1,
        this.limit1
      );
      if (res.data.status) {
        this.packGit = res.data.data.data || [];
        this.packGit.forEach((item) => {
          if (item.an_as.length > 0) {
            let tagString = "";
            item.an_as.forEach((i) => {
              tagString += i.name + ",";
            });
            item.tags = tagString;
          }
        });

        this.total1 = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    //关闭弹窗
    handleClose(done) {
      done();
      this.page1 = 1;
      // this.getList();
    },
  },
  mounted() {
    this.getList();
    // this.sdhadj();
  },
};
</script>

<style scoped>
.salesAmount {
  margin-bottom: 10px;
  margin-right: 10px;
  font-size: 18px;
  color: rgba(249, 100, 34, 1);
}
</style>